<!-- 商品详情 => 确认订单 -->
<template>
	<view class="order-wrap">
		<view v-if="!onHide" class="order-padding">
			<!-- 地址栏 -->
				<view class="head_box"  @tap="jump('/pages/user/address/list', { from: 'order' })">
					<view class="add-address-box u-flex u-flex-1" v-if="!addressId">
						<view class="box-bg u-p-30 u-flex-1 u-flex u-row-between">
							<text class="select-notice">请选择收货地址</text>
							<text class="u-iconfont uicon-arrow-right" style="color: #bfbfbf;"></text>
						</view>
					</view>
					<view class="add-address-box u-p-30"  v-else>
						<view class="top u-flex">
							<text class="name">{{ addressData.consignee }}</text>
							<text class="phone">{{ addressData.phone }}</text>
							<text class="tag" v-show="addressData.is_default == 1">默认</text>
						</view>
						<view class="detail u-flex u-row-between">
							<view class="address">
								{{ addressData.areaName }}{{ addressData.address }}
							</view>
							<text class="u-iconfont uicon-arrow-right rightPos" style="color: #bfbfbf;"></text>
						</view>
					</view>
				</view>
			
				<view class="u-m-b-10">
					<!-- 确认订单商品卡片 -->
					<view class="goods-list" v-for="g,index in perGoodsList.orderItemList" :key="index">
						<view class="goods-card u-p-30">
							<ljshop-mini-card :title="g.name" :image="g.thumbnail">
								<template #describe>
									<view class="order-sku u-ellipsis-1">
										<text class="order-num" v-for="(item, index) in JSON.parse(g.specifications)" :key="index">
											{{ item }}
										</text>
									</view>
								</template>
								<template #cardBottom>
									<view class="goods-price u-flex  u-row-between">
										<view class="">
											<text v-show="orderType === 'score'">{{ g.score }}积分+</text>
											<text style="font-weight: 600;">￥{{ g.price.toFixed(2)  }}</text>
										</view>
										<u-number-box
											v-model="g.quantity"
											:min="miniNum"
											:step="setUp"
											:max="maxStep"
											:disabled="isActivity ? true : false"
											:long-press="false"
											@change="changeNum"
										></u-number-box>
									</view>
								</template>
							</ljshop-mini-card>
						</view>
					</view>
					
					<view class="logistic item-list u-flex u-row-between" >
						<view class="item-title">配送方式</view>
						<view class="u-flex" style="flex-direction: column;">
							<view class="detail">{{ orderPre.defaultShippingMethod.name}}</view>
							<!-- <text class="u-iconfont uicon-arrow-right" style="color: #bfbfbf;"></text> -->
						</view>
					</view>
					<view class="remark-box u-flex item-list u-p-30">
						<view class="item-title">备注</view>
						<input class="item-input" placeholder="请输入备注" placeholder-class="input-pl" type="text" v-model="remark" />
					</view>
					<view class="u-flex u-row-between item-list border-top" style="background: #fafafa; border-top: 1rpx solid #f2f2f2;">
						<view class="item-title" style="color: rgba(80, 80, 80, 1);">小计</view>
						<view class="u-flex">
							<text class="price" style="margin: 0;">￥{{ (price * totalNum).toFixed(2) || '0.00' }}</text>
						</view>
					</view>
					
			
					<view class="bottomBox">
						<!-- 备注 -->
							<!-- <view class="uni-list">
								<view class="uni-list-cell uni-list-cell-pd">
									<view class="uni-list-cell-db">使用余额</view>
									<switch checked @change="switchChange"/>
								</view>
							</view> -->
						
						<!-- <view class="contitle" v-if="isSubsidy">
							已补贴金额{{ getRebate }}元
						</view> -->
						<!-- 积分 -->
						<view class="score item-list u-flex u-row-between" v-show="orderType === 'score'">
							<view class="u-flex"><text class="item-title">积分</text></view>
							<view class="price">-{{ orderPre.score_amount || 0 }}积分</view>
						</view>
			
						<!-- 活动优惠 -->
						<u-collapse
							v-if="orderPre.activity_discount_infos && orderPre.activity_discount_infos.length && Number(orderPre.activity_discount_money)"
							event-type="close" :arrow="true" :accordion="true" arrowColor="#bfbfbf"
							:head-style="{ background: '#fff', height: '100rpx' }">
							<u-collapse-item>
								<block slot="title">
									<view style="width: 680rpx;padding-right: 0;" class="u-flex u-row-between item-list">
										<view class="item-title">活动优惠</view>
										<view class="u-flex">
											<text class="price"
												style="margin-right: 0;">-￥{{ orderPre.activity_discount_money || '0.00' }}</text>
										</view>
									</view>
								</block>
								<view class="" v-for="item in orderPre.activity_discount_infos" :key="item.activity_id">
									<view class="u-flex u-row-between item-list" v-if="item.activity_type !== 'free_shipping'">
										<view class="item-title">{{ item.activity_title }}</view>
										<view class="u-flex">
											<text class="price"
												style="color: #666;">-￥{{ item.activity_discount_money || '0.00' }}</text>
										</view>
									</view>
								</view>
							</u-collapse-item>
						</u-collapse>
						
						<!-- 支付方式 -->
						<view class="logistic item-list u-flex u-row-between" style="margin-top: 20rpx;" >
							<view class="item-title">支付方式</view>
							<view class="u-flex">
								<view class="detail">{{ orderPre.defaultPaymentMethod.name}}</view>
								<!-- <text class="u-iconfont uicon-arrow-right" style="color: #bfbfbf;"></text> -->
							</view>
						</view>
						<!-- 价格 -->
						<view class="price-box  u-flex u-row-between item-list">
							<view class="item-title u-flex u-col-center">
								<view class="u-m-r-10">运费</view>
<!-- 								<view class="activity-title" v-if="Number(orderPre.freight) > 0">活动减￥
									{{ orderPre.freight }}
									</view> -->
							</view>
							<view class="u-flex">
								<text style="font-size: 25rpx;color: #666;">{{ freight.toFixed(2) > 0 ? freight.toFixed(2) : '包邮'}}</text>
							</view>
						</view>
						<!-- 选择优惠券 -->
						<sh-select-coupon
							v-if="onShowCoupon() && !isSubsidy"
							ref="conSelect"
							:couponList="couponList"
							@change="selectCoupon"
							@lookMoreCon="lookMoreCon"
							>
						</sh-select-coupon>
						<view class="contitle"
							v-if="!isSubsidy"
							>
								可优惠金额{{ getRebate }}元
						</view>
						<!-- 发票 -->
						<view v-if="orderPre && Number(orderPre.invoice_amount)"
							class="u-flex u-row-between item-list u-p-20 border-top">
							<view class="item-title">申请发票</view>
							<view class="u-flex u-col-center" @tap="onInvoice">
								<text class="selected-invoice"
									style="font-size: 28rpx;color:#c4c4c4;">{{ selectedInvoice }}</text>
								<text class="u-iconfont uicon-arrow-right" style="color: #bfbfbf;"></text>
							</view>
						</view>
					</view>
				</view>
			
				<!-- 底部 -->
				<view class="foot-box-wrap">
					<view class="foot-box u-flex u-row-between safe-area-inset-bottom" style="flex">
						<view class="u-flex" style="width:100%">
							<view class="num">
								共<span style="margin: 0 5rpx;">{{ totalNum }}</span>件
							</view>
							<view class="all-money" style="display: flex;margin: 0 10rpx;">
								<view class="" style="color: #ef5a27 !important;display: flex;align-items: center;">
									<text style="color: black;font-size: 28rpx;">合计:</text>
									<view class="" style="font-size: 28rpx;font-weight: bold;">￥
									<span>{{ (orderPre.price + freight - orderPre.subsidy).toFixed(2) || '0.00' }}</span>
									<!-- <span style="font-size: 35rpx;" v-else> {{ (orderPre.amount - getRebate ).toFixed(2) || '0.00' }}</span> -->
									</view>
								</view>
								<view class="" style="color:#808080;font-size: 20rpx;margin-top: 6rpx;margin-left: 14rpx;">
									<span v-show="!isSubsidy">共减: {{ (((orderPre.price + freight).toFixed(2) - orderPre.amount.toFixed(2))).toFixed(2) || '0.00' }} 元</span>
									<span v-show="isSubsidy">已补贴：￥{{ orderPre.subsidy }}</span>
								</view>
							</view>
						</view>
						<button class="cu-btn sub-btn" @tap="subOrder" :disabled="isDisabled"
							hover-class="btn-hover">提交订单</button>
					</view>
				</view>
			
				<!-- 发票弹窗 -->
				<u-popup v-model="showInvoice" @close="showInvoice = false" safe-area-inset-bottom mode="bottom"
					:closeable="false" border-radius="20">
					<view class="invoice-modal page_box">
						<view class="invoice-head u-flex u-col-center">
							<view class="head-nav u-flex u-col-center u-row-center" @tap="changeInvoiceType('person')">
								<text class="nav-title " :class="{ 'nav-title--active': invoiceType === 'person' }">个人</text>
								<view v-show="invoiceType === 'person'" class="head-nav--active"></view>
							</view>
							<view class="head-nav u-flex u-col-center u-row-center" @tap="changeInvoiceType('company')">
								<text class="nav-title"
									:class="{ 'nav-title--active': invoiceType === 'company' }">企/事业单位</text>
								<view v-show="invoiceType === 'company'" class="head-nav--active"></view>
							</view>
						</view>
						<view class="invoice-content content_box">
							<u-form
								:labelStyle="{ 'font-size': '28rpx', 'font-weight': '600', color: '#595959', 'padding-left': '20rpx' }"
								label-position="left" :model="invoiceForm.model" :rules="invoiceForm.rules" ref="invoiceRef"
								:errorType="['toast']">
								<u-form-item class="u-p-r-20" label-width="150" label="名称:" prop="header_name">
									<u-input placeholder="请填写名称" v-model="invoiceForm.model.header_name" type="text"></u-input>
								</u-form-item>
								<u-form-item class="u-p-r-20" v-if="invoiceType === 'company'" label-width="220" label="纳税人识别号:"
									prop="tax_no">
									<u-input placeholder="请输入纳税人识别号" v-model="invoiceForm.model.tax_no" type="text"></u-input>
								</u-form-item>
								<u-form-item class="u-p-r-20" label-width="150" label="手机号:" prop="mobile">
									<u-input placeholder="请输入填写手机号" v-model="invoiceForm.model.mobile" type="number"></u-input>
								</u-form-item>
							</u-form>
						</view>
						<view class="invoice-foot">
							<view class="invoite-price u-flex u-col-center u-row-center u-m-b-40">
								<text class="price-title">可开票金额：</text>
								<text class="price-num">{{ orderPre.invoice_amount }}元</text>
							</view>
							<view class="u-flex u-col-center u-row-around u-p-b-30">
								<button class="cancel-btn u-reset-button" @tap="cancelInvoice">取消</button>
								<button class="save-btn u-reset-button" @tap="saveInvoice">确定</button>
							</view>
						</view>
					</view>
				</u-popup>
			
				<!-- 配送方式弹窗 -->
				<u-popup v-model="showExpressType" @close="showExpressType = false" safe-area-inset-bottom mode="bottom"
					:closeable="false" border-radius="20">
					<!-- 配送方式tab-->
					<view class="express-type page_box">
						<view class="express-type__head head-box u-flex u-col-center">
							<view class="express-type__head-nav u-flex u-col-center u-row-center"
								v-for="(nav, index) in expressType" :key="nav.id" @tap="changeExpressType(nav.value)"
								v-if="inExpressType.includes(nav.value)">
								<text class="head-nav__title"
									:class="{ 'head-nav__title--active': expressTypeCur === nav.value }">{{ nav.title }}</text>
								<view :class="expressClass" v-show="expressTypeCur === nav.value"></view>
							</view>
						</view>
						<view class="express-type__bottom u-flex u-row-between u-p-b-20"
							v-show="expressTypeCur !== 'selfetch' || (expressTypeCur == 'selfetch' && lat)">
							<button class="u-reset-button cancel-btn" @tap="hideExpressType">取消</button>
							<button class="u-reset-button save-btn" @tap="saveExpressType">确定</button>
						</view>
					</view>
				</u-popup>
				<!-- 配送时间弹窗 -->
			</view>
			<view v-else class="netErr">
				<image src="https://image.hzwltb69.com/app/date/2023/暂无商品.png" mode="widthFix"></image>
				获取商品信息失败，请稍后重试
			</view>
		</view>
</template>

<script>
	import shSelectCoupon from './components/sh-select-coupon.vue';
	import { mapMutations, mapActions, mapState, mapGetters } from 'vuex';
	import Auth from '@/ljshop/permission/index.js';
	export default {
		components: {
			shSelectCoupon
		},
		data() {
			return {
				goodsNum: 1,
				onHide: false,
				maxStep: 999,
				platform: this.$platform.get(),
				totalNum: 0,
				couponList: [], //优惠券列表
				addressData: {}, //收货地址
				addressId: 0, //收货地址ID
				customStyle: {
					//自定义按钮样式
					width: '210rpx',
					lineHeight: '70rpx',
					background: 'linear-gradient(90deg, rgba(233, 180, 97, 1), rgba(238, 204, 137, 1))',
					boxShadow: ' 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22)',
					borderRadius: '100rpx',
					fontSize: '28rpx',
					border: 'none',
					color: '#fff',
					margin: '0'
				},
				isDisabled: false, //提交
				showCheckTime: false, //配送时间弹窗。
				checkTime: {}, //配送时间数据
				showExpressType: false, //配送方式弹窗
				expressTypeMap: {
					express: '物流快递',
					selfetch: '到店/自提',
					store: '商家配送',
					autosend: '自动发货'
				},
				expressType: [
					//配送方式
					{
						id: 'e1',
						title: '物流快递',
						value: 'express'
					},
					{
						id: 'e2',
						title: '到店/自提',
						value: 'selfetch'
					},
					{
						id: 'e3',
						title: '商家配送',
						value: 'store'
					},
					{
						id: 'e4',
						title: '自动发货',
						value: 'autosend'
					}
				],
				storeList: [], //门店列表
				storeInfo: {
					id: 0,
					name: '',
					dispatch_text: ''
				}, //自提点商家信息
				from: '',
				orderType: '',
				grouponBuyType: 'alone',
				grouponId: 0,
				goodsList: [], //传递过来的参数
				perGoodsList: {}, //确认单订单商品
				currentGoodsId: 0, //当前商品id.
				currentSkuId: 0, //商品的规格ID
				remark: '',
				orderPre: {
					price: 0,
					amount: 0
				},
				couponId: 0,
				couponPrice: '选择优惠券',
				expressTypeCur: '',
				inExpressType: [], //当前商品支持的配送方式。

				isProtocol: true, //自提协议。
				selfPhone: '', //编辑手机号
				getFocus: false, //获取焦点。
				checkType: '自提',
				checkTimeCur: 0, //默认选中时间。
				checkTimeId: 'c1', //锚点用
				checkDayCur: 0, //默认日期
				lat: 0, //地理位置
				lng: 0,
				alldata:{},
                setUp: 1,
				miniNum:1,
				showInvoice: false, //申请发票
				invoiceType: 'person',
				selectedInvoice: '不开具发票',
				invoiceForm: {
					model: {
						header_name: '',
						mobile: '',
						tax_no: '',
						type: 'person'
					},
					rules: {
						mobile: [{
								required: true,
								message: '请输入手机号',
								trigger: ['change', 'blur']
							},
							{
								validator: (rule, value, callback) => {
									return this.$u.test.mobile(value);
								},
								message: '手机号码不正确',
								trigger: ['change', 'blur']
							}
						],
						header_name: [{
							required: true,
							message: '请填写名称',
							trigger: ['change', 'blur']
						}]
					}
				},
				conIndex: -1,
				rebate: 0,
				page: 0,
				freight: 0,
				isActivity: false,
				isSubsidy: false,
				amount:0,
				price:0
			};
		},
		computed: {
			...mapGetters(['initStore']),
			expressClass() {
				let cl = 'head-nav--active';
				const { expressType, expressTypeCur } = this;
				if (expressTypeCur === 0) {
					cl = 'head-nav__left--active';
				}
				if (expressTypeCur === expressType.length - 1) {
					cl = 'head-nav__right--active';
				}
				return cl;
			},
			getRebate:{
				get() {
					return (this.rebate * this.totalNum).toFixed(2)
				}
			}
		},
		onShow() {
			// 监听选择自提点
			uni.$once('SELECT_STORE', res => {
				this.storeInfo = JSON.parse(res.storeInfo);
			});
			// 监听地址
			uni.$on('SELECT_ADDRESS', res => {
				if (res.addressData) {
					this.addressData = JSON.parse(res.addressData);
					this.addressId = this.addressData.id;
					this.getFreight()
				} else {
					this.addressId = 0;
				}
				res.addressData && uni.$off('SELECT_ADDRESS');
			});
		},
		async onLoad() {
			this.goodsList = this.$Route.query.goodsList;
      this.getDefaultAddress()
		},
		methods: {
			onShowCoupon(){
				// if(!this.isActivity) return false
				if(!this.isSubsidy) return true
				return true
			},
			getFreight(){
				let arr = [
					{
						skuId: this.goodsList[0].skuId,
						quantity: this.totalNum
					}
				]
				this.$http('order.getPrepareOrder',{
					cartItems: arr,
					receiverId: this.addressId
				})
				.then(res=>{
					if(res.code == 1){
						this.freight = res.data.freight
					}
				})
			},
			...mapActions(['getCartList']),
			// 切换发票类型
			changeInvoiceType(type) {
				this.invoiceType = type;
				this.invoiceForm.model.type = type;
			},
			switchChange: function (e) {
				console.log('switch1 发生 change 事件，携带值为', e.detail.value)
			},
			lookMoreCon(){
				this.page++
				this.getCouponList()
			},
			// 获取可用的优惠券列表
			getCouponList(){
				let that = this
				that.$http('coupons.useCon',{
					skuId: that.goodsList[0].skuId,
					current: that.page,
					pageSize: 10
				})
				.then(res=>{
					if(res.data.list.length == 0){
						this.$refs.conSelect.onEnd = true
					}
					this.couponList.length == 0 ? this.couponList = res.data.list : this.couponList = this.couponList.concat(res.data.list)
					this.rebate = res.data.rebate
				})
			},
			// 点击开发票
			onInvoice() {
				this.showInvoice = !this.showInvoice;
				this.$nextTick(() => {
					if (this.showInvoice) {
						this.invoiceForm.model.type = 'person';
						this.$refs.invoiceRef.setRules(this.invoiceForm.rules);
					}
				});
			},
			// 发票确认取消
			cancelInvoice() {
				this.selectedInvoice = '不开具发票';
				Object.keys(this.invoiceForm.model).map(key => (this.invoiceForm.model[key] = ''));
				this.showInvoice = false;
			},
			saveInvoice() {
				this.$refs.invoiceRef.validate(valid => {
					if (valid) {
						if (this.invoiceType === 'company' && !this.invoiceForm.model.tax_no) {
							this.$u.toast('请输入纳税人识别号');
						}
						this.selectedInvoice = this.invoiceForm.model.header_name;
						this.showInvoice = false;
					}
				});
			},
			// plus(e) {
			// 	this.totalNum = e.value
			// 	this.orderPre.price = this.perGoodsList.orderItems[0].price* this.totalNum
			// 	this.orderPre.amount = this.perGoodsList.orderItems[0].price* this.totalNum
			// 	if(this.conIndex !== -1){
			// 		this.orderPre.amount = this.orderPre.amount -= this.couponList[this.conIndex].price
			// 	}
			// },
			// 数量
			changeNum(e) {
				this.totalNum = e.value
				let price =  this.price * this.totalNum
				this.orderPre.amount = price
				// 存在优惠券 进行优惠后计算
				if(this.conIndex !== -1){
					let conPrice = this.couponList[this.conIndex].price
					// 如果所选券的面值小于可优惠金额 只减免所选券的金额
					if(conPrice < this.getRebate){
						this.orderPre.price = price - conPrice
					}else{
						// 所选券的面值大于可用优惠金额 减免所有可用优惠金额
						this.orderPre.price = price - this.getRebate
					}
				}else{
					this.orderPre.price = price
				}
				this.getFreight()
			},
			// 初始化
			init() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
			   this.initDate()
        this.getPre();
        this.getCouponList()
			},
			jump(path, parmas) {
				this.$Router.push({
					path: path,
					query: parmas
				});
			},
			// 格式化选择时间
			initDate() {
				let week = {
					0: '周日',
					1: '周一',
					2: '周二',
					3: '周三',
					4: '周四',
					5: '周五',
					6: '周六'
				};
				let now = new Date().getTime();
				let today = this.$u.timeFormat(now);
				let tomorrow = this.$u.timeFormat(now + 86400000);
				let aftertomorrow = this.$u.timeFormat(now + 172800000);
				let week1 = week[new Date().getDay()];
				let week2 = week[new Date(now + 86400000).getDay()];
				let week3 = week[new Date(now + 172800000).getDay()];
				let obj = {
					day: [{
							title: '今天（' + week1 + '）',
							value: today
						},
						{
							title: '明天（' + week2 + '）',
							value: tomorrow
						},
						{
							title: '后天（' + week3 + '）',
							value: aftertomorrow
						}
					],
					time: ['08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00',
						'18:00', '19:00'
					]
				};
				this.checkTime = obj;
			},
			// 格式日期
			check(type, index) {
				if (type == 'time') {
					this.checkTimeCur = index;
					this.checkTimeId = this.checkTime['time'][index].split(':')[[0]];
				}
				if (type == 'day') {
					this.checkDayCur = index;
				}
			},
			// 获取位置
			async getLocation() {
				let authState = await new Auth('userLocation').check();
				// #ifdef MP ||　APP-PLUS
				authState &&
					uni.getLocation({
						type: 'gcj02',
						success: res => {
							this.lng = res.longitude;
							this.lat = res.latitude;
							this.getStoreAddress();
						},
						fail: err => {
							console.log('确认订单自提位置：', err);
						}
					});
				// #endif
				// #ifdef H5
				uni.getLocation({
					type: 'gcj02',
					success: res => {
						this.lng = res.longitude;
						this.lat = res.latitude;
						this.getStoreAddress();
					}
				});
				// #endif
			},
			// 获取商品支持的自提点。
			getStoreAddress() {
				let that = this;
				that.$http('goods.storeAddress', {
					id: that.currentGoodsId,
					latitude: that.lat,
					longitude: that.lng
				}).then(res => {
					if (res.code == 1) {
						that.storeInfo = res.data.data[0];
						that.storeList = res.data.data;
					}
				});
			},
			// 订单信息
			getPre() {
				let that = this;
				let cartItems = [{
					skuId:that.goodsList[0].skuId,
					quantity:that.goodsList[0].count
				}]
				that.$http('order.procheckout', {
						receiverId:that.addressId,
						cartItems
				}).then(res => {
					if (res.code == 1) {
						// that.isActivity = res.isActivity
						that.orderPre = res.data;
						that.perGoodsList = res.data.orders[0];
						that.totalNum = res.data.quantity;
						this.setUp = res.data.orders[0].orderItemList[0].attribute.stepNum
						this.miniNum = res.data.orders[0].orderItemList[0].attribute.minNum
						this.freight = res.data.freight,
						this.price = res.data.price,
						this.amount = res.data.amount
						if(res.data.subsidy > 0){
							that.isSubsidy = true
							// that.orderPre.price -= res.data.subsidy
						}
					}else{
						that.onHide = true
					}
				});
			},
			// 提交订单
			subOrder() {
				let that = this;
				if(that.addressId==0){
					uni.showToast({
						title: '请选择收货地址',
						icon: 'error'
					})
				 	return ;
				}
				let cartItems = [{
					skuId:that.goodsList[0].skuId,
					quantity:this.totalNum
				}]
				that.$http(
					'order.procreate', {
						receiverId:that.addressId,
						cartItems,
						voucherId:that.couponId,
						promoteId:that.$Route.query.shareUId
					},
					'提交中...'
				).then(res => {
					that.isDisabled = false;
						
					if (res.code == 1) {
						that.$Router.replace({
							path:"/pages/order/payment/method",
							query: {
								orderId: res.data.orderSns[0],
								outTradeNo:res.data.outTradeNo
							}
						});
					}else{
						uni.showToast({
							icon:'error',
							title: res.message
						})
					}
				});
		        that.isDisabled = true;
			},

			// 初始地址
			getDefaultAddress() {
		     	let that= this
				that.$http('address.defaults', {
				UId:uni.getStorageSync("UId"),
          current:1,
          pageSize:10
				}).then(res => {
          if (res.data.list.length > 0) {
            for (let i = 0; i < res.data.list.length; i++) {
              if (res.data.list[i].isDefault) {
                that.addressData = res.data.list[i] //收货地址
                that.addressId = res.data.list[i].id
              }
            }
          }
          this.init();
				});
			},
			// 选择优惠券 减免金额
			selectCoupon(index) {
				this.conIndex = index
				const price = this.price * this.totalNum
				this.orderPre.amount = price + this.freight
				if(index == -1){
					this.couponId = ''
					this.orderPre.amount = this.perGoodsList.orderItemList[0].price * this.totalNum
					return
				}
				if(this.couponList[index].id){
					// 重置价格 为组价格
					// this.orderPre.amount = this.orderPre.price.toFixed(2)
					this.couponId = this.couponList[index].id
					// 如果所选券的面值小于可优惠金额 只减免所选券的金额
					if(this.couponList[index].price < this.getRebate){
						this.orderPre.price = price - this.couponList[index].price
					}else{
					// 所选券的面子大于可用优惠金额 减免所有可用优惠金额
						// this.orderPre.amount = this.perGoodsList.orderItemList[0].price * this.totalNum
						this.orderPre.price = price - this.getRebate
					}
				}
			},

			// 显示配送方式弹窗
			async onSelExpressType() {
				this.showExpressType = true;
			
		 
			},
			// 关闭配送方式弹窗
			hideExpressType() {
				this.showExpressType = false;
				this.changeGoodsList();
			},
			// 保存配送方式
			saveExpressType() {
				if (this.expressTypeCur === 'selfetch') {
					if (!this.storeInfo) {
						this.$u.toast('暂无自提点，请选择其他配送方式');
						return false;
					}
					if (!this.isProtocol) {
						this.$u.toast('请先勾选门店协议');
						return false;
					}
				}

				this.showExpressType = false;
				this.changeGoodsList();
			    
			},

			// 更改提交数据
			changeGoodsList() {
				this.goodsList.forEach(goods => {
					if (goods.goods_id == this.currentGoodsId && this.currentSkuId == goods.sku_price_id) {
						goods.dispatch_type = this.expressTypeCur;
						goods.dispatch_phone = this.selfPhone;
						goods.dispatch_date = this.checkTime['day'][this.checkDayCur].value + ' ' + this.checkTime[
							'time'][this.checkTimeCur] + ':00';
						if (this.expressTypeCur == 'selfetch') {
							if (!this.storeInfo) {
								this.$u.toast('暂无自提点，请选择其他配送方式');
								return false;
							}
							goods.store_id = this.storeInfo.id;
						}
						goods.checkDayCur = this.checkDayCur;
						goods.checkTimeCur = this.checkTimeCur;
					}
				});
			},

			// 选择快递方式
			changeExpressType(cur) {
				this.expressTypeCur = cur;
				this.getFocus = false;
				cur === 'selfetch' && !this.lat && this.getLocation();
			},

			// 是否同意协议
			checkProtocol() {
				this.isProtocol = !this.isProtocol;
			},
			// 选择配送时间
			checkExpressTime(type) {
				switch (type) {
					case 'store':
						this.checkType = '配送';
						break;
					case 'selfetch':
						this.checkType = '自提';
						break;
					default:
						this.checkType = '自提';
				}
				this.showCheckTime = !this.showCheckTime;
			}
		}
	};
</script>

<style lang="scss" scoped>
	.order-padding{
		width: 100%;
		box-sizing: border-box;
		padding: 16rpx 12rpx 0 12rpx;
	}
	.uni-switch-input:before {
	    content: ' ';
	    position: absolute;
	    top: 0;
	    left: 0;
	    width: 50px;
	    height: 30px;
	    border-radius: 15px;
	
	    transition: transform 0.3s;
	}
	.uni-switch-input.uni-switch-input-checked {
	    border-color: #007aff;
	    background-color: #007aff;
	}
	.uni-list {
	    background-color: #FFFFFF;
	    position: relative;
	    width: 100%;
	    display: flex;
	    flex-direction: column;
	}
	.uni-list-cell-pd {
	    padding: 0.6875rem 0.9375rem;
	}
	
	.uni-list-cell {
	    position: relative;
	    display: flex;
	    flex-direction: row;
	    justify-content: space-between;
	    align-items: center;
	}
	// 发票弹窗
	.invoice-modal {
		width: 750rpx;
		background-color: #fff;
		border-radius: 20rpx 20rpx 0 0;
		height: 700rpx;
		overflow: visible;
	
	.invoice-foot {
			.price-title {
				font-size: 28rpx;
				font-weight: 400;
				color: #333333;
			}

			.price-num {
				font-size: 28rpx;
				font-weight: 500;
				color: #eab662;
			}

			.cancel-btn {
				width: 335rpx;
				line-height: 74rpx;
				background: rgba(238, 238, 238, 1);
				border-radius: 37rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: rgba(51, 51, 51, 1);
			}

			.save-btn {
				width: 335rpx;
				line-height: 74rpx;
				background: linear-gradient(90deg, rgba(233, 180, 97, 1), rgba(238, 204, 137, 1));
				border-radius: 37rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: rgba(255, 255, 255, 1);
			}
		}

		.invoice-head {
			width: 100%;
			height: 80rpx;
			background: #f8e3bd;
			border-radius: 20rpx 20rpx 0 0;

			.head-nav {
				width: (750rpx/2);
				position: relative;
				height: 100%;
			}

			.nav-title {
				font-size: 24rpx;
				font-weight: 500;
				color: #666;
				position: relative;
				z-index: 6;
			}

			.nav-title--active {
				color: #a8700d;
				font-size: 26rpx;
			}

			.head-nav--active {
				position: absolute;
				left: 50%;
				transform: translateX(-50%);
				bottom: 0;
				background: #fff;
				width: 100%;
				height: 80rpx;
				background-color: #fff;
				border-radius: 20rpx 20rpx 0px 0px;

				&::after {
					content: '';
					display: block;
					width: 40rpx;
					height: 80rpx;
					position: absolute;
					transform: skewX(20deg);
					background: #fff;
					border-top-right-radius: 20rpx;
					top: 0;
					right: -15rpx;
				}

				&::before {
					content: '';
					display: block;
					width: 40rpx;
					height: 80rpx;
					position: absolute;
					transform: skewX(-20deg);
					background: #fff;
					border-top-left-radius: 20rpx;
					top: 0;
					left: -15rpx;
				}
			}
		}
	}

	// 收货地址栏
	.head_box {
		background-color: #fff;
		border-radius: 18rpx;
		background-image: url('https://zh69xx.oss-cn-beijing.aliyuncs.com/app/date/2023/confirm/c0a082d02f4a9072cc95af14d3fddb2.png');
		background-repeat: no-repeat;
		background-size: 100%;
		background-position: bottom;
	}

	.add-address-box {
		min-height: 100rpx;
		background: url($IMG_URL+'/imgs/order/order_address_line.png') no-repeat;
		background-size: 100% auto;
		background-position: bottom center;
		position: relative;

		.select-notice {
			font-weight: 600;
			color: red;
			line-height: 40rpx;
		}

		.name,
		.phone {
			font-size: 30rpx;
			font-weight: 500;
		}

		.phone {
			margin: 0 20rpx;
		}

		.tag {
			background: rgba(233, 191, 113, 0.2);
			border-radius: 6rpx;
			padding: 0 16rpx;
			line-height: 38rpx;
			color: #a8700d;
			font-size: 22rpx;
		}

		.detail {
			.address {
				margin-top: 20rpx;
				width: 560rpx;
				font-size: 26rpx;
				
				font-weight: 400;
				color: rgba(153, 153, 153, 1);
				line-height: 40rpx;
				
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}
	}

	// 备注
	.remark-box {

		background: #fff;
		padding: 25rpx;

		.item-input {
			flex: 1;
			text-align: end;
			font-size: 28rpx;
		}

		.input-pl {
			color: #c4c4c4;
		}
	}

	// 商品卡片
	.goods-list {
		background: #fff;
		margin-top: 20rpx;
		border-radius: 18rpx;

		.goods-card {
			min-height: 200rpx;

			.goods-price {
				font-size: 30rpx;
				font-weight: 500;
				width: 480rpx;
				color: #333333;

				.goods-num {
					font-size: 28rpx;
					color: #c4c4c4;
				}
			}

			.order-sku {
				font-size: 24rpx;
				font-weight: 400;
				color: rgba(153, 153, 153, 1);
				width: 440rpx;
				margin-bottom: 20rpx;

				.order-num {
					margin-right: 10rpx;
				}
			}
		}
	}

	.item-list {
		height: 80rpx;
		background: #fff;
		padding: 0 25rpx;

		.item-title {
			font-size: 28rpx;
			margin-right: 20rpx;

			.activity-title {
				font-size: 26rpx;
				color: #999;
			}
		}

		.detail {
			font-size: 28rpx;
			color: #333;
		}

		.origin-price {
			font-size: 26rpx;
			color: #666;
			text-decoration: line-through;
		}

		.price {
			font-size: 26rpx;
			font-weight: 600;
			color: #ff0000;
			margin-right: 40rpx;
		}

		.sel-coupon {
			font-size: 26rpx;
			color: #c4c4c4;
			margin-right: 20rpx;
		}
	}
	.foot-box-wrap {
		height: calc(100rpx + env(safe-area-inset-bottom) / 2);
		padding-bottom: calc(env(safe-area-inset-bottom) / 2);
		position: relative;
		width: 100%;
		z-index: 70;
	}

	.foot-box {
		position: fixed;
		display: flex;
		align-items: center;
		width: 100%;
		height: calc(100rpx + env(safe-area-inset-bottom) / 2);
		// border-top: 1rpx solid #eeeeee;
		background-color: #fff;
		z-index: 998;
		bottom: 0;
		left: 0;
		right: 0;
		padding-bottom: calc(env(safe-area-inset-bottom) / 2);
		padding: 0 30rpx;
	
	.btn-hover {
			color: #fff;
		}

		.num {
			font-size: 26rpx;
			color: #999;
		}

		.all-money {
			// margin: 0 60rpx 0 20rpx;
			.price {
				color: #ff0000;
			}
		}

		.sub-btn {
			width: 210rpx;
			line-height: 70rpx;
			background: linear-gradient(90deg, #ef9137, #ec602b);
			border-radius: 50rpx;
			font-size: 28rpx;
			color: #fff;
		}
	}

	// 弹窗之配送方式
	// 配送方式
	.express-type {
		width: 750rpx;
		background-color: #fff;
		border-radius: 20rpx 20rpx 0 0;
		height: 700rpx;
		overflow: visible;
	
	.express-type__head {
			width: 100%;
			height: 80rpx;
			background: #f8e3bd;
			border-radius: 20rpx 20rpx 0 0;

			&-nav {
				width: (750rpx/4);
				position: relative;
				height: 100%;
			}

			.head-nav--active {
				position: absolute;
				left: 50%;
				transform: translateX(-50%);
				bottom: 0;
				background: #fff;
				width: 100%;
				height: 80rpx;
				background-color: #fff;
				border-radius: 20rpx 20rpx 0px 0px;

				&::after {
					content: '';
					display: block;
					width: 40rpx;
					height: 80rpx;
					position: absolute;
					transform: skewX(20deg);
					background: #fff;
					border-top-right-radius: 20rpx;
					top: 0;
					right: -15rpx;
				}

				&::before {
					content: '';
					display: block;
					width: 40rpx;
					height: 80rpx;
					position: absolute;
					transform: skewX(-20deg);
					background: #fff;
					border-top-left-radius: 20rpx;
					top: 0;
					left: -15rpx;
				}
			}

			.head-nav__left--active {
				position: absolute;
				left: 50%;
				transform: translateX(-50%);
				bottom: 0;
				background: #fff;
				width: 100%;
				height: 74rpx;
				background-color: #fff;
				border-radius: 20rpx 20rpx 0px 0px;

				&::after {
					content: '';
					display: block;
					width: 40rpx;
					height: 74rpx;
					position: absolute;
					transform: skewX(20deg);
					background: #fff;
					border-top-right-radius: 20rpx;
					top: 0;
					right: -15rpx;
				}
			}

			.head-nav__right--active {
				position: absolute;
				left: 50%;
				transform: translateX(-50%);
				bottom: 0;
				background: #fff;
				width: 100%;
				height: 74rpx;
				background-color: #fff;
				border-radius: 20rpx 20rpx 0px 0px;

				&::before {
					content: '';
					display: block;
					width: 40rpx;
					height: 74rpx;
					position: absolute;
					transform: skewX(-20deg);
					background: #fff;
					border-top-left-radius: 20rpx;
					top: 0;
					left: -15rpx;
				}
			}

			.head-nav__title {
				font-size: 24rpx;
				font-weight: 500;
				color: #666;
				position: relative;
				z-index: 6;
			}

			.head-nav__title--active {
				color: #a8700d;
				font-size: 26rpx;
			}
		}

		.express-type__content {
			.empty-address {
				height: 120rpx;
				padding: 0 25rpx;
				font-size: 28rpx;

				font-weight: 400;
				color: rgba(153, 153, 153, 1);
			}

			// 无定位
			.location-box {
				height: 500rpx;
				justify-content: center;

				.nolocation-img {
					width: 74rpx;
					height: 90rpx;
					margin-bottom: 40rpx;
				}

				.location-title {
					font-size: 35rpx;

					font-weight: bold;
					color: rgba(70, 53, 27, 1);
					margin-bottom: 20rpx;
				}

				.location-tip {
					font-size: 28rpx;

					font-weight: 400;
					color: rgba(153, 153, 153, 1);
					margin-bottom: 40rpx;
				}

				.open-location {
					width: 492rpx;
					line-height: 70rpx;
					background: linear-gradient(90deg, rgba(233, 180, 97, 1), rgba(238, 204, 137, 1));
					box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
					border-radius: 35rpx;
					font-size: 28rpx;

					font-weight: 500;
					color: rgba(255, 255, 255, 1);
				}
			}

			// 快递
			.express-address {
				position: relative;
				padding: 30rpx 25rpx;
				background: url($IMG_URL+'/imgs/order/address_bg.png') no-repeat;
				background-size: 430rpx 300rpx;
				background-position: top right;

				.express-top {
					margin-bottom: 20rpx;
					width: 550rpx;
					text-align: left;

					.address {
						font-size: 28rpx;
						font-weight: 500;
						color: rgba(51, 51, 51, 1);
						line-height: 40rpx;
						text-align: left;
					}

					.dispatch-notice {
						font-size: 28rpx;

						font-weight: 500;
						color: rgba(51, 51, 51, 1);
						line-height: 40rpx;
						text-align: left;
					}

					.address-location {
						position: absolute;
						right: 60rpx;
						top: 30rpx;

						.location-img {
							width: 80rpx;
							height: 90rpx;
						}

						.location-text {
							font-size: 18rpx;

							font-weight: 500;
							color: rgba(51, 51, 51, 1);
						}
					}

					.tag {
						background: rgba(233, 191, 113, 0.2);
						border-radius: 6rpx;
						padding: 0 16rpx;
						line-height: 38rpx;
						color: #a8700d;
						font-size: 22rpx;
						margin-right: 20rpx;
					}

					.tag1 {
						background: rgba(53, 190, 105, 0.2);
						border-radius: 6rpx;
						padding: 0 16rpx;
						line-height: 38rpx;
						color: #1bbc50;
						font-size: 22rpx;
						margin-right: 20rpx;
					}

					.address-guide {
						position: absolute;
						right: 25rpx;
						top: 40rpx;
						color: #999999;
					}
				}

				.express-content {
					margin-bottom: 20rpx;

					.box-line {
						width: 1rpx;
						height: 61rpx;
						border-left: 1rpx solid rgba(238, 238, 238, 1);
						margin: 0 40rpx;
					}

					.phone-box1 {

						.name,
						.phone {
							font-size: 26rpx;

							font-weight: 400;
							color: rgba(102, 102, 102, 1);
						}

						.phone {
							margin-left: 20rpx;
						}
					}

					.time-box,
					.phone-box {
						text-align: left;
						min-height: 120rpx;

						.box-title {
							font-size: 24rpx;

							font-weight: 400;
							color: #666;
							padding-bottom: 10rpx;
						}

						.box-text {
							font-size: 24rpx;

							font-weight: 500;
							color: #333;
						}

						.edit-phone {
							width: 160rpx;
							font-size: 24rpx;

							font-weight: 500;
							color: #333;
						}

						.box-icon {
							font-size: 28rpx;
							color: #999;
							display: inline-block;
							width: 40rpx;
							text-align: center;
							line-height: 40rpx;
						}
					}
				}

				.express-bottom {
					.protocol {
						font-size: 24rpx;

						font-weight: 400;
						color: rgba(102, 102, 102, 1);

						.protocol-text {
							color: #6487a4;
						}
					}
				}
			}
		}

		.express-type__bottom {
			height: 90rpx;
			padding: 0 30rpx;

			.cancel-btn {
				width: 335rpx;
				line-height: 74rpx;
				background: rgba(238, 238, 238, 1);
				border-radius: 37rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: rgba(51, 51, 51, 1);
			}

			.save-btn {
				width: 335rpx;
				line-height: 74rpx;
				background: linear-gradient(90deg, rgba(233, 180, 97, 1), rgba(238, 204, 137, 1));
				border-radius: 37rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: rgba(255, 255, 255, 1);
			}
		}
	}

	// 选择配送给时间
	.checkTime-box {
		background: rgba(255, 255, 255, 1);
		border-radius: 20rpx 20rpx 0px 0px;
		height: 720rpx;
		text-align: center;

		.checkTime-head {
			font-size: 32rpx;

			font-weight: 500;
			color: rgba(51, 51, 51, 1);
			line-height: 100rpx;
			position: relative;
		}

		.checkTime-foot {
			height: 100rpx;

			.save-btn {
				width: 690rpx;
				line-height: 80rpx;
				background: linear-gradient(90deg, rgba(240, 199, 133, 1), rgba(246, 214, 157, 1));
				border-radius: 40rpx;
				font-size: 30rpx;

				font-weight: 500;
				color: rgba(255, 255, 255, 1);
			}
		}

		.checkTime-content {
			.checkTime-content__left {
				height: 100%;
				width: 190rpx;
				background: #f5f5f5;

				.left-item {
					font-size: 26rpx;

					font-weight: 500;
					color: rgba(51, 51, 51, 1);
					height: 100rpx;
					width: 100%;
				}
			}

			.checkTime-content__right {
				flex: 1;
				height: 100%;
				overflow-y: auto;

				.right-item {
					font-size: 26rpx;

					font-weight: 500;
					color: rgba(51, 51, 51, 1);
					width: 100%;
					text-align: center;
					border-bottom: 1rpx solid rgba(#dfdfdf, 0.6);
					margin: 0 30rpx;
					line-height: 100rpx;
				}
			}

			.item--active {
				font-size: 26rpx;

				font-weight: 500;
				color: rgba(168, 112, 13, 1) !important;
				background-color: #fff;
			}
		}
	}
	.contitle{
		padding: 0 25rpx;
		height: 100rpx;
		line-height: 100rpx;
		background: #fff;
		// border-top: 1rpx solid rgba(223, 223, 223, 0.5);
		display: flex;
		justify-content: flex-end;
		font-size: 25rpx;
	}
	.netErr{
		height: 100vh;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		font-size: 25rpx;
		image{
			width: 234rpx;
			height: 208rpx;
		}
	}
	
	.rightPos{
		position: absolute;
		right: 40rpx;
		bottom: 60rpx;
	}
	.bottomBox{
		border-radius: 18rpx;
	}
</style>
